package com.openlogic.logic.controller.datasource;

import java.util.List;

import org.noear.solon.annotation.Body;
import org.noear.solon.annotation.Controller;
import org.noear.solon.annotation.Inject;
import org.noear.solon.annotation.Mapping;
import org.noear.solon.annotation.Post;
import org.noear.solon.core.handle.Result;
import org.noear.solon.validation.annotation.Validated;

import com.openlogic.common.core.web.controller.BaseController;
import com.openlogic.common.core.web.validate.V_A_E;
import com.openlogic.datasource.api.dto.SqlConsoleDto;
import com.openlogic.datasource.api.vo.SqlConsoleVo;
import com.openlogic.logic.service.datasource.SqlConsoleService;

/**
 * @ClassName: SqlConsoleController
 * @Description: SQL控制台Controller
 * @author weiyongpeng
 * @date 2024年11月24日 上午10:09:06
 */
@Controller
@Mapping("/sql")
public class SqlConsoleController extends BaseController {

	@Inject
	private SqlConsoleService sqlConsoleService;

	@Post
	@Mapping("/run")
	public Result<List<SqlConsoleVo>> sqlRun(@Body @Validated SqlConsoleDto sqlConsoleDto) {
		List<SqlConsoleVo> list = sqlConsoleService.sqlRun(sqlConsoleDto);
		return Result.succeed(list);
	}

	@Post
	@Mapping("/stop")
	public Result<String> sqlStop(@Body @Validated({ V_A_E.class }) SqlConsoleDto sqlConsoleDto) {
		sqlConsoleService.sqlStop(sqlConsoleDto);
		return Result.succeed();
	}

}
